{% extends "task_manage.html" %}
{% block task_report %}
<div>
    <!--模块列表-->
    <h4 class="sub-header"><span class="label label-primary">任务报告</span></h4>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>id</th>
                <th>任务名称</th>
                <th>失败的用例数</th>
                <th>错误的用例数</th>
                <th>跳过的用例数</th>
                <th>总的用例数</th>
                <th>耗时</th>
                <th>创建日期</th>
                <th>报告详情</th>

            </tr>
            </thead>
            <tbody>
            {% for each_data in report_data %}
            <tr>
                <td>{{ each_data.id }}</td>
                <td>{{ each_data.name}}</td>
                <td>{{ each_data.failure }}</td>
                <td>{{ each_data.error }}</td>
                <td>{{ each_data.skipped }}</td>
                <td>{{ each_data.count_case }}</td>
                <td>{{ each_data.running_time }}</td>
                <td>{{ each_data.create_time | date:"Y-m-d H:i:s" }}</td>
<!--                <td>-->
<!--                    <div style="margin-right: 8px;">-->
<!--                        <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal" onclick="SeeLog({{ each_data.id }})">-->
<!--                            查看-->
<!--                        </button>-->
<!--                    </div>-->
<!--                </td>-->
                <td>
                    <div style="margin-right: 8px;">
                        <button class="btn btn-primary btn-sm"  onclick="SeeHtml({{ each_data.id }})">
                            查看
                        </button>
                    </div>

                </td>
                {% endfor %}
            </tr>
            </tbody>
        </table>
    </div>
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        标题
                    </h4>
                </div>
                <div class="modal-body" id="see_log">
                    在这里添加一些文本
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

<link href="http://cdn.bootcss.com/zTree.v3/3.5.23/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/zTree.v3/3.5.23/js/jquery.ztree.all.js"></script>
<script type="text/javascript">

    function SeeLog(task_id){
        console.log(task_id)
        $.post(
            '/task_manage/see_log/',
            {report_id:task_id},
            function(resp){
            document.querySelector("#see_log").innerHTML = resp.data[1]
            document.querySelector("#myModalLabel").innerText = resp.data[0]
            console.log(resp.data)
            })
    }

    function SeeHtml(task_id){
        console.log(task_id)
        $.post(
                '/task_manage/see_log/',
                {report_id:task_id},
                function(resp){
                    // 可行方法一
                     let newWindow = window.open('','','');//创建一个新窗口
                     newWindow.document.write(resp.data[1]);//把数据write到新窗口名
                    // window.location.href =
                     //newWindow.location.href = resp.data[1]
                })
    }

</script>

{% endblock %}